package ${model.packageName}.api.facade;

import java.util.List;
import java.util.ArrayList;
import java.util.Map;

import org.springframework.stereotype.Service;

import ${model.packageName}.api.bean.request.${model.initUpperName}QueryRequest;
import ${model.packageName}.api.bean.request.${model.initUpperName}PageRequest;
import ${model.packageName}.api.bean.response.${model.initUpperName}InfoResponse;
import ${model.packageName}.api.converter.${model.initUpperName}ApiConverter;
import ${model.packageName}.model.${model.initUpperName}Model;
import ${model.packageName}.service.${model.initUpperName}ReadService;

import io.terminus.common.model.PageInfo;
import io.terminus.common.model.Paging;
import io.terminus.common.model.Response;
import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class ${model.initUpperName}ReadFacadeImpl implements ${model.initUpperName}ReadFacade {
	
	private final ${model.initUpperName}ReadService ${model.initLowerName}ReadService;	
	private final ${model.initUpperName}ApiConverter ${model.initLowerName}ApiConverter;

	@Override
	public Response<${model.initUpperName}InfoResponse> view${model.initUpperName}(${model.initUpperName}QueryRequest request) {
		${model.initUpperName}Model model = ${model.initLowerName}ReadService.view${model.initUpperName}(${model.initLowerName}ApiConverter.get(request));
		if(model == null){
			model = new ${model.initUpperName}Model();
		}
		return Response.ok(${model.initLowerName}ApiConverter.model2InfoResponse(model));
	}

	@Override
	public Response<List<${model.initUpperName}InfoResponse>> list${model.initUpperName}(${model.initUpperName}QueryRequest request) {
		List<${model.initUpperName}Model> modelList = ${model.initLowerName}ReadService.list${model.initUpperName}(${model.initLowerName}ApiConverter.get(request));
		if(modelList == null){
			modelList = new ArrayList<${model.initUpperName}Model>();
		}
		return Response.ok(${model.initLowerName}ApiConverter.modelList2InfoResponseList(modelList));
	}
	
	@Override
	public Response<Paging<${model.initUpperName}InfoResponse>> page${model.initUpperName}(${model.initUpperName}PageRequest request) {
		Map<String, Object> params = ${model.initLowerName}ApiConverter.model2Map(${model.initLowerName}ApiConverter.get(request));
		PageInfo pageInfo = new PageInfo(request.getPageNo(), request.getPageSize());
		Paging<TestUserBankCardModel> modelPage = ${model.initLowerName}ReadService.page${model.initUpperName}(params, pageInfo.getOffset(), pageInfo.getLimit());
		return Response.ok(${model.initLowerName}ApiConverter.modePage2InfoPage(modelPage));
	}

}
